<template>
  <div class="app-container">
    <!-- <div class="total-layout">
    </div>
    <div class="un-handle-layout">
    </div>
    <div class="overview-layout">
    </div>
    <div class="statistics-layout">
    </div>
    </div>-->
    <div>欢迎登录后台系统</div>
  </div>
</template>

<script>
import $ from "jquery";
import { getInfo } from "@/api/login";
import { encode } from "@/utils/base64";
import {IA300_GetHardwareId} from '@/utils/IA300'
export default {
  name: "home",
  data() {
    return {
      currentUserInfo: {},
    };
  },
  created() {
    //this.testJquery();
    this.getCurrentUser();
  },
  methods: {
    getCurrentUser() {
      getInfo().then((res) => {
        if (res.code == 200) {
          this.currentUserInfo = res.data;
          console.log("当前用户信息" + JSON.stringify(this.currentUserInfo));
          this.getLoginMessage();
        }
      });
    },
    getLoginMessage() {
      var that = this;
      let password122 = that.currentUserInfo["password_122"];
      password122 = encode(password122);
      var uid = "";
      var sczzid = that.currentUserInfo["sczzid"];
      console.log("sczzid====" + sczzid);
      if (null != sczzid && "null" != sczzid && "" != sczzid) {
        console.log("1111");
        uid = sczzid;
      } else {
        uid = IA300_GetHardwareId();
        console.log("uid=====" + uid);
      }
      if (uid == "") {
        return false;
      }
      $.ajax({
        url: "http://127.0.0.1:8886/police/getLoginMessage",
        dataType: "json",
        data: {
          jiaojingUrlPrefix: that.currentUserInfo["shengwangUrl"],
          memberId: that.currentUserInfo["storeid"],
          userName: that.currentUserInfo["username_122"],
          password: password122,
          szzsid: uid,
        },
        type: "post",
        success: function (ret) {
          if (ret.success) {
            var message = ret.data.message;
            var vercode = ret.data.vericode;
            var jsessionId = ret.data.jsessionId;
            var md5Key = ret.data.md5Key;
            var md5Value = ret.data.md5Value;
            that.autoLogin(message, vercode, jsessionId, md5Key, md5Value);
          } else {
            console.log("获取122登录token失败.");
          }
        },
        error: function () {
          console.log("获取122登录token失败.");
        },
      });
    },
    autoLogin(message, vercode, jsessionId, md5Key, md5Value) {
      var userName122 = this.currentUserInfo["username_122"];
      var password122 = this.currentUserInfo["password_122"];
      var jiaojingUrl = this.currentUserInfo["shengwangUrl"];
      if (userName122 == "") {
        return false;
      }
      if (password122 == "") {
        return false;
      }
      password122 = encode(password122);
      var uid = "";
      var sczzid = this.currentUserInfo["sczzid"];
      if ("null" != sczzid && "" != sczzid) {
        uid = sczzid;
      } else {
        uid = IA300_GetHardwareId();
      }
      if (uid == "") {
        return false;
      }
      $.ajax({
        url: "http://127.0.0.1:8886/police/driverAutoLogin",
        dataType: "json",
        data: {
          memberId: this.currentUserInfo["storeid"],
          jiaojingUrlPrefix: jiaojingUrl,
          message: message,
          szzsid: uid,
          userName: userName122,
          password: password122,
          csessionid: vercode,
          jsessionId: jsessionId,
          md5Key: md5Key,
          md5Value: md5Value,
          source: 0,
        },
        type: "post",
        success: function (ret) {
          if (ret.success) {
            alert(ret.message);
          } else {
            alert(ret.message);
          }
        },
        error: function () {
          console.log("122登录连接失败,请稍后重试.");
        },
      });
    },
  },
};
</script>

<style scoped>
.app-container {
  margin-top: 40px;
  margin-left: 120px;
  margin-right: 120px;
}

.total-frame {
  border: 1px solid #dcdfe6;
  padding: 20px;
  height: 100px;
}

.total-icon {
  color: #409eff;
  width: 60px;
  height: 60px;
}

.total-title {
  position: relative;
  font-size: 16px;
  color: #909399;
  left: 70px;
  top: -50px;
}

.total-value {
  position: relative;
  font-size: 18px;
  color: #606266;
  left: 70px;
  top: -40px;
}

.un-handle-layout {
  margin-top: 20px;
  border: 1px solid #dcdfe6;
}

.layout-title {
  color: #606266;
  padding: 15px 20px;
  background: #f2f6fc;
  font-weight: bold;
}

.un-handle-content {
  padding: 20px 40px;
}

.un-handle-item {
  border-bottom: 1px solid #ebeef5;
  padding: 10px;
}

.overview-layout {
  margin-top: 20px;
}

.overview-item-value {
  font-size: 24px;
  text-align: center;
}

.overview-item-title {
  margin-top: 10px;
  text-align: center;
}

.out-border {
  border: 1px solid #dcdfe6;
}

.statistics-layout {
  margin-top: 20px;
  border: 1px solid #dcdfe6;
}
</style>
